package com.example.jetpacktest.viewmodel

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import com.example.jetpacktest.R
import com.example.jetpacktest.databinding.ActivityViewModelTest1Binding

class ViewModelTest1Activity : AppCompatActivity() {

    private lateinit var test1ViewModel: Test1ViewModel

    private lateinit var binding: ActivityViewModelTest1Binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this, R.layout.activity_view_model_test1)
        test1ViewModel = ViewModelProvider(this).get(Test1ViewModel::class.java)
        binding.test1ViewModel = test1ViewModel
        binding.lifecycleOwner = this //必须设置，否则更新了viewModel里面的数据，界面并不会同步更新
        test1ViewModel.getInitUser()
    }

}